package model.entity;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import model.entity.container.ProductContainer;
import model.entity.container.StorageUnit;
import model.exceptions.InvalidNameException;

import org.junit.Before;
import org.junit.Test;

import common.Result;

public class ProductTest
{

  private Product          product;
  private ProductContainer productConatainer;

  @Before
  public void setUp() throws InvalidNameException
  {
    product = new Product("2340234750");
    productConatainer = new StorageUnit("Kitchen");
  }

  @Test
  public void testValidateAddToProductContainer()
  {

    // invalid-null container
    Result result = product.validateAddToProductContainer(null);
    assertFalse(result.getStatus());

    // valid
    Result result2 = product.validateAddToProductContainer(productConatainer);
    assertTrue(result2.getStatus());
    product.addToProductContainer(productConatainer);

    // invalid-already in the container
    Result result3 = product.validateAddToProductContainer(productConatainer);
    assertFalse(result3.getStatus());

  }

  @Test
  public void testAddToProductContainer()
  {

    // invalid
    product.addToProductContainer(null);
    assertEquals(0, product.getSizeOfProductContainers());

    // valid
    product.addToProductContainer(productConatainer);
    assertEquals(1, product.getSizeOfProductContainers());

  }

  @Test
  public void testValidateRemoveFromProductContainer()
  {

    // invalid-null container
    Result result = product.validateRemoveFromProductContainer(null);
    assertFalse(result.getStatus());

    // invalid-is not in the container
    Result result3 = product.validateRemoveFromProductContainer(productConatainer);
    assertFalse(result3.getStatus());

    // valid
    product.addToProductContainer(productConatainer);
    Result result2 = product.validateRemoveFromProductContainer(productConatainer);
    assertTrue(result2.getStatus());
  }

  @Test
  public void testRemoveFromProductContainer()
  {

    // invalid
    product.addToProductContainer(productConatainer);
    product.removeFromProductContainer(null);
    assertEquals(1, product.getSizeOfProductContainers());

    // valid
    product.removeFromProductContainer(productConatainer);
    assertEquals(0, product.getSizeOfProductContainers());

  }

  @Test
  public void testValidateDescription()
  {

    // invalid-null description
    Result result = product.validateDescription(null);
    assertFalse(result.getStatus());

    // invalid-"" description
    Result result2 = product.validateDescription("");
    assertFalse(result2.getStatus());

    // valid
    Result result3 = product.validateDescription("RetiveFinder");
    assertTrue(result3.getStatus());

  }

  @Test
  public void testValidateShelfLife()
  {

    // invalid-negative
    Result result = product.validateShelfLife(-1);
    assertFalse(result.getStatus());

    // valid
    Result result3 = product.validateShelfLife(3);
    assertTrue(result3.getStatus());

  }

  @Test
  public void testValidateThreeMonthSupply()
  {

    // invalid-negative
    Result result = product.validateThreeMonthSupply(-1);
    assertFalse(result.getStatus());

    // valid
    Result result3 = product.validateThreeMonthSupply(3);
    assertTrue(result3.getStatus());

  }

}
